package com.abp.service.impl;

import com.abp.entity.Book;
import com.abp.entity.BookLibary;
import com.abp.mapper.BookMapper;
import com.abp.qpage.QPage;
import com.abp.service.BookService;
import com.abp.utils.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {
    // 自定义图书服务方法实现

    /**
     * 分页查询
     * @param qPage
     * @return
     */
    @Override
    public IPage getPageList(QPage qPage, Book obj) {
        IPage iPage = new Page(qPage.getPage(), qPage.getRows());
        List<Book> mapList = this.baseMapper.getPageList(iPage,obj);
        return iPage.setRecords(mapList);
    }

    /**
     * 新增
     * @param obj
     * @return
     */
    @Override
    public Result insert(Book obj) {
        obj.setStatus(1);
        this.save(obj);
        return Result.reOk("恭喜，新增成功");
    }

    /**
     * 修改
     * @param obj
     * @return
     */
    @Override
    public Result updates(Book obj) {
        this.updateById(obj);
        return Result.reOk("恭喜，修改成功");
    }


}
